package com.billowsoft.tool.train.service;

import java.util.HashMap;
import java.util.Map;

public class LoginService {

	public static boolean login(String username, String pwd, String randCode)
			throws Exception {

		Map<String, String> loginParams = new HashMap<String, String>();
		loginParams.put("loginUser.user_name", username);
		loginParams.put("user.password", pwd);
		loginParams.put("randCode", randCode);

		String loginResponse = HttpUtil.sendFormBasedRequest(
				HttpClientFactory.getHttpClient(), Configuration.LOGIN_URL,
				loginParams);
		if (loginResponse.contains("我的订单")) {
			// 登录成功
			return true;
		} else if (loginResponse.contains("请稍后再试")) {
			// 用户过多，重复登陆
			return false;
		} else {
			throw new RuntimeException("信息输入错误，请检查用户名，密码和验证码是否正确！");
		}
	}

}
